import {defineStore} from "pinia";

export const userInfo = defineStore('user', {
    //存储全局变量
    state:()=>({
        user:{
            token:'',
            id:null,
            doctorRoleId:null,
            phone:'',
            username:'',
            doctorAvatar:'',
            state:null
        },         //  用户信息
        loggedIn:false,  //  是否登录
    }),
    //同步修改状态信息
    actions:{
        updateUser(user){
            this.user = user;
        },
        updateLoginStatus(status){
            this.loggedIn = status;
        },
        updateToken(token) {
            this.user.token = token;
        },
        clearUser() {
            this.user = {}
            this.loggedIn = false
        }
    },
    persist: {
        enable: true,
        storage: localStorage,
    }
})